#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

def dot_prod(u, v):
    return sum(ui * vi for (ui, vi) in zip(u, v))

def comp():
    return One * oneof(-1, 1) * oneof(Half, 1, 2, 3)

while True:
    # Entradas
    with display_block('Entradas'):
        m, n = One * oneof(1, 2, 3, 4), One * oneof(1, 2, 3, 4)
        c = One * oneof(Half, 1, 3 * Half, 2, 3, 4, 5) * oneof(-1, 1)
        x0, y0, z0 = comp(), comp(), comp()
        if (m, n) == (One, One):
            continue

        func = x ** m + c * x * y + y ** n
        Pto = (x0, y0, z0)

    # Resultados auxiliares
    with display_block('Variáveis auxiliares'):
        fx0 = diff(func, x).subs([(x, x0), (y, y0)])
        fy0 = diff(func, x).subs([(x, x0), (y, y0)])
        Norm = (-fx0, -fy0, 1)
        NormSinal = (fx0, fy0, 1)
        NormZ = (fx0, fy0, 0)
        NormXYZ = (-diff(func, x), -diff(func, y), 1)
        delta_r = (x - x0, y - y0, z - z0)

    # Resultados
    with display_block('Respostas'):
        eqCorreta = Eq(dot_prod(Norm, delta_r), 0)
        sinalNormal = Eq(dot_prod(NormSinal, delta_r), 0)
        normalZ = Eq(dot_prod(NormZ, delta_r), 0)
        semR0 = Eq(dot_prod(NormZ, (x, y, z)), 0)
        semR0Z = Eq(dot_prod(NormZ, (x - x0, y - y0, z)), 0)
        semPto = Eq(expand(dot_prod(NormXYZ, delta_r)), 0)
        somaSemSubs = Eq(dot_prod(NormXYZ, (1, 1, 1)), 0)

    break
